#############################################################
#### Targeting - packages
#############################################################
## Cornelius Erfort, erfortco@hu-berlin.de

# Install/load packages from CRAN
p_needed <- c(
  "httr",
  "jsonlite",
  "lubridate",
  "dplyr",
  "plyr",
  "stringr",
  "readr",
  "ggplot2",
  "ggrepel",
  "ggmap",
  "maps",
  "rgdal",
  "rgeos",
  "classInt",
  "eurostat",
  "scales",
  "broom",
  "openxlsx",
  "margins",
  "tidyr",
  "readxl",
  "rvest",
  "purrr",
  "stargazer",
  "coefplot",
  "data.table",
  "sjPlot",
  "sjmisc",
  "haven",
  "gridExtra",
  "pbapply",
  "quanteda",
  "ineq",
  "extrafont",
  "ggwordcloud",
  "knitr",
  "bibtex",
  "sjlabelled",
  "miceadds",
  "ggnewscale",
  "digest",
  "pbapply",
  "jpeg",
  "png",
  "english",
  "labelled",
  "ggpattern",
  "rnaturalearth",
  "rnaturalearthdata",
  "quanteda.textplots",
  "quanteda.textstats",
  "ggrepel",
  "scales")


packages <- rownames(installed.packages())
p_to_install <- p_needed[!(p_needed %in% packages)]
if (length(p_to_install) > 0) {
  install.packages(p_to_install)
}
lapply(p_needed, require, character.only = TRUE)

# Load fonts
font_import(pattern = "lmroman*")

par(family = "Latin Modern Roman")
theme_update(text = element_text(family = "Latin Modern Roman"))

# Clean up
rm("p_needed", "p_to_install", "packages")
